/**
 * Created by liuzengrong on 2019/8/16.
 */
import React from 'react';
import { connect } from 'dva';
import StandardModule from '@/components/hyperspace/modules/StandardModule';
import CostList from '../../../components/Business/costList';
import ServiceOrderDetail from '../tradeflow/components/ServiceOrderDetail';

let costList: any = {};


let serviceOrderDetail: any = {};


/**
 * 自定义模块
 */
// @ts-ignore
const LocalModule: React.FC = ({ todoServiceOrder, dispatch }) => (
  <div>
    <StandardModule
      data={todoServiceOrder.data}
      dictionary={[
        {
          name: 'goodsContent',
          desc: '商品',
          dataType: 'string',
        },
      ]}
      config={{
        common: {
          formItemOptions: {
            username: {
              rules: [{ required: true, message: '该字段不能为空！' }],
            },
          },
        },
        search: {
          fields: ['username', 'mobile', 'email'], // 查询条件
          tabs: {
            field: 'status',
            tabItems: [
              {
                title: '售前',
                value: 'TO_AUDIT',
                active: true,
              },
              {
                title: '处理中',
                value: 'AUDIT_PASS',
              },
              {
                title: '已完成',
                value: 'AUDIT_FAIL',
              },
              {
                title: '异常',
                value: 'ONLINE',
              },
            ],
          }, // 状态栏
        },
        list: {
          url: '/api/serviceOrder/query',
          fields: [
            'serviceOrderNo',
            'goodsContent',
            'customerName',
            'mobile',
            'status',
            'creator',
          ], // 列表字段
          format: {
            username: {
              render: (value: any) => `格式化 - ${value}`,
            },
          },
          extensions: {
            operations: [
              (record: any) => (
                <div>
                  <a
                    onClick={() => {
                      if (serviceOrderDetail) serviceOrderDetail.handleOpen();
                    }}
                  >
                    详情
                  </a>
                  <div className="ant-divider" />
                  <a
                    onClick={() => {
                      costList.handleOpen();
                    }}
                  >
                    费用明细
                  </a>
                  <div className="ant-divider" />
                  <a onClick={() => {}}>
                    作废
                  </a>
                </div>
              ),
            ],
          },
        },
      }}
      namespace="todoServiceOrder"
      dispatch={dispatch}
    />
    <CostList
      wrappedComponentRef={(inst: any) => {
        costList = inst;
        return costList;
      }}
      {...costList}
    />

    {/* eslint-disable-next-line no-return-assign */}
    <ServiceOrderDetail wrappedComponentRef={(inst: any) => (serviceOrderDetail = inst)}
                  {...serviceOrderDetail}
                  visible

    />
  </div>
);

// @ts-ignore
export default connect(({ todoServiceOrder }) => ({
  todoServiceOrder,
}))(LocalModule);
